#include "headerform.h"

#include <QDebug>
#include <QStyleOption>
#include <QToolButton>
#include <QStackedWidget>
#include <QPixmap>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPainter>
#include <QLabel>
#include <QPushButton>

HeaderForm::HeaderForm(QWidget *parent) :
    QWidget(parent),
    m_bSettingsBtnDown(false),
    m_bHelpBtnDown(false)
{
    setObjectName("HeaderForm");

    m_pLogoLabel=new QLabel;
    m_pLogoLabel->setFixedWidth(170);
    m_pLogoLabel->setAlignment(Qt::AlignTop|Qt::AlignHCenter);
    m_pLogoLabel->setObjectName("m_pLogoLabel");
        m_pLogoLabel->setPixmap(QPixmap("://images/logo.png"));
    m_pSettingButton=new QPushButton(tr("Settings"));
    m_pSettingButton->setObjectName("m_pSettingButton");
    m_pHelpButton=new QPushButton(tr("Help"));
    m_pHelpButton->setObjectName("m_pHelpButton");
    m_pUserButton=new QPushButton(tr("User"));
    m_pUserButton->setObjectName("m_pUserButton");
    m_pLogoutButton=new QPushButton(tr("Logout"));
    m_pLogoutButton->setObjectName("m_pLogoutButton");

    QHBoxLayout *settingHLabyout=new QHBoxLayout;
    settingHLabyout->setMargin(0);
    settingHLabyout->addWidget(m_pSettingButton);
    settingHLabyout->addWidget(m_pHelpButton);
    settingHLabyout->addStretch(1);
    settingHLabyout->addWidget(m_pUserButton);
    settingHLabyout->addWidget(m_pLogoutButton);

    QVBoxLayout *settingVLayout=new QVBoxLayout;
    settingVLayout->setMargin(0);
    settingVLayout->addStretch(1);
    settingVLayout->addLayout(settingHLabyout);

    QHBoxLayout *logoHLayout=new QHBoxLayout;
    //    logoHLayout->setMargin(0);
    logoHLayout->setContentsMargins(10,10,10,0);
    logoHLayout->addWidget(m_pLogoLabel);
    logoHLayout->addLayout(settingVLayout);

    setLayout(logoHLayout);

    //connects
    connect(m_pSettingButton,SIGNAL(clicked(bool)),
            this,SLOT(slotSettings()));
    connect(m_pHelpButton,SIGNAL(clicked(bool)),
            this,SLOT(slotHelp()));
    connect(m_pUserButton,SIGNAL(clicked(bool)),
            this,SLOT(slotUser()));
    connect(m_pLogoutButton,SIGNAL(clicked(bool)),
            this,SLOT(slotLogout()));
}

HeaderForm::~HeaderForm()
{
}

void HeaderForm::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);

    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

void HeaderForm::slotSettings()
{
    if(m_bSettingsBtnDown)
        m_pSettingButton->setDown(false);
    else
        m_pSettingButton->setDown(true);

    m_bSettingsBtnDown=!m_bSettingsBtnDown;

    m_pHelpButton->setDown(false);
    m_pUserButton->setDown(false);
    m_pLogoutButton->setDown(false);

    emit sigSettings();
}

void HeaderForm::slotHelp()
{

}

void HeaderForm::slotUser()
{

}

void HeaderForm::slotLogout()
{

}



ToolsForm::ToolsForm(QWidget *parent):
    QWidget(parent)
{
    setObjectName("ToolsForm");

    m_pStackedWdg=new QStackedWidget;
    QHBoxLayout *layout=new QHBoxLayout;
    layout->addWidget(m_pStackedWdg);

    setLayout(layout);

    initSettings();
}

ToolsForm::~ToolsForm()
{

}

void ToolsForm::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);

    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

void ToolsForm::slotUserPressed()
{
    m_pUserButton->setIcon(QIcon("://images/icon-userSettings-c.png"));
}

void ToolsForm::slotUserReleased()
{
    m_pUserButton->setIcon(QIcon("://images/icon-userSettings-n.png"));
}

void ToolsForm::slotInputPressed()
{
    m_pInputButton->setIcon(QIcon("://images/icon-input-c.png"));
}

void ToolsForm::slotInputReleased()
{
    m_pInputButton->setIcon(QIcon("://images/icon-input-n.png"));
}

void ToolsForm::slotOutputPressed()
{
    m_pOutputButton->setIcon(QIcon("://images/icon-output-c.png"));
}

void ToolsForm::slotOutputReleased()
{
    m_pOutputButton->setIcon(QIcon("://images/icon-output-n.png"));
}

void ToolsForm::slotPlanPressed()
{
    m_pPlanButton->setIcon(QIcon("://images/icon-plan-c.png"));
}

void ToolsForm::slotPlanReleased()
{
    m_pPlanButton->setIcon(QIcon("://images/icon-plan-n.png"));
}

void ToolsForm::slotSeniorPressed()
{
    m_pSeniorButton->setIcon(QIcon("://images/icon-sSettings-c.png"));
}

void ToolsForm::slotSeniorReleased()
{
    m_pSeniorButton->setIcon(QIcon("://images/icon-sSettings-n.png"));
}

void ToolsForm::initSettings()
{
    QWidget *settingsWdg=new QWidget;
    m_pStackedWdg->addWidget(settingsWdg);

    m_pUserButton=new QToolButton;
    m_pUserButton->setCheckable(true);
    m_pUserButton->setObjectName("m_pUserButton");
    m_pUserButton->setFixedSize(80,80);
    m_pUserButton->setIconSize(QSize(50,50));
    m_pUserButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    m_pUserButton->setIcon(QIcon("://images/icon-userSettings-n.png"));
    m_pUserButton->setText(tr("User"));

    m_pInputButton=new QToolButton;
    m_pInputButton->setObjectName("m_pInputButton");
    m_pInputButton->setFixedSize(80,80);
    m_pInputButton->setIconSize(QSize(50,50));
    m_pInputButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    m_pInputButton->setIcon(QIcon("://images/icon-input-n.png"));
    m_pInputButton->setText(tr("Input"));

    m_pOutputButton=new QToolButton;
    m_pOutputButton->setObjectName("m_pOutputButton");
    m_pOutputButton->setFixedSize(80,80);
    m_pOutputButton->setIconSize(QSize(50,50));
    m_pOutputButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    m_pOutputButton->setIcon(QIcon("://images/icon-output-n.png"));
    m_pOutputButton->setText(tr("Output"));

    m_pPlanButton=new QToolButton;
    m_pPlanButton->setObjectName("m_pPlanButton");
    m_pPlanButton->setFixedSize(80,80);
    m_pPlanButton->setIconSize(QSize(50,50));
    m_pPlanButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    m_pPlanButton->setIcon(QIcon("://images/icon-plan-n.png"));
    m_pPlanButton->setText(tr("Plan"));

    m_pSeniorButton=new QToolButton;
    m_pSeniorButton->setObjectName("m_pSeniorButton");
    m_pSeniorButton->setFixedSize(80,80);
    m_pSeniorButton->setIconSize(QSize(50,50));
    m_pSeniorButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    m_pSeniorButton->setIcon(QIcon("://images/icon-sSettings-n.png"));
    m_pSeniorButton->setText(tr("Senior"));

    QHBoxLayout *hLayout=new QHBoxLayout;
    hLayout->addWidget(m_pUserButton);
    hLayout->addWidget(m_pInputButton);
    hLayout->addWidget(m_pOutputButton);
    hLayout->addWidget(m_pPlanButton);
    hLayout->addWidget(m_pSeniorButton);
    hLayout->addStretch(1);

    settingsWdg->setLayout(hLayout);

    //connects
    connect(m_pUserButton,SIGNAL(pressed()),
            this,SLOT(slotUserPressed()));
    connect(m_pUserButton,SIGNAL(released()),
            this,SLOT(slotUserReleased()));
    connect(m_pInputButton,SIGNAL(pressed()),
            this,SLOT(slotInputPressed()));
    connect(m_pInputButton,SIGNAL(released()),
            this,SLOT(slotInputReleased()));
    connect(m_pOutputButton,SIGNAL(pressed()),
            this,SLOT(slotOutputPressed()));
    connect(m_pOutputButton,SIGNAL(released()),
            this,SLOT(slotOutputReleased()));
    connect(m_pPlanButton,SIGNAL(pressed()),
            this,SLOT(slotPlanPressed()));
    connect(m_pPlanButton,SIGNAL(released()),
            this,SLOT(slotPlanReleased()));
    connect(m_pSeniorButton,SIGNAL(pressed()),
            this,SLOT(slotSeniorPressed()));
    connect(m_pSeniorButton,SIGNAL(released()),
            this,SLOT(slotSeniorReleased()));
}
